﻿using Flurl;
using Flurl.Http;
using NineApi.Responses;
using System.Diagnostics;
using System.Net.Http.Headers;

namespace NineApi
{
    public class Api
    {
        public static readonly string _url = "https://pay.wx6d.com/";  //"https://localhost:5001/";

        private static readonly string apis = "api.php";
        private static readonly string submits = "submit.php";
        private static readonly string check = "Submit/Mym_Get.php";
        public static async Task<TResponse> GetJsonAsync<TResponse>(string url, object queryParameters = null)
        {
            var response = await url
                .WithTimeout(TimeSpan.FromSeconds(10))
                .GetJsonAsyncWithLowercaseParams<TResponse>(queryParameters);
            return response;
        }
        public static async Task<string?>  GetAsync(string url, object queryParameters = null)
        {
            var req = url.WithTimeout(TimeSpan.FromSeconds(10)).SetQueryParamsToLowercase(queryParameters);
            var response=await req.GetStringAsync();
            return response;
        }

       

        public static async Task<TenantResponse>QueryTenantInfo(TenantRequest tenantRequest)
        {
            return await GetJsonAsync<TenantResponse>(_url + apis, tenantRequest);
        }
        public static async Task<OrdersResponse> QueryOrdersInfo(OrdersRequest tenantRequest)
        {
            return await GetJsonAsync<OrdersResponse>(_url + apis, tenantRequest);
        }

        public static async Task<string?> Pay(PayRequest  payRequest)
        {
            return await GetAsync(_url + submits, payRequest);
        }

        public static async Task<CheckResponse>Check(CheckRequest checkRequest)
        {
            return await GetJsonAsync<CheckResponse>(_url +check, checkRequest);
        }
    }
}